// serie_profile_algo.h

#ifndef DODO_SERIE_PROFILE_ALGO_H
#define DODO_SERIE_PROFILE_ALGO_H

#include <stdexcept>

#include <quigon/basic/constants.h>
#include <quigon/basic/basic_profile.h>
#include <quigon/basic/basic_serie.h>
#include <quigon/basic/math_utils.h>
#include <quigon/basic/basic_utils.h>

namespace quigon
{
// require Tpro: Like a Profile:
// [size_t] like vector
// [string] like the Profile, to access attributes.
// require Tser: Like a Serie:
// .interp_val()
template<class Tpro, class Tser>
Tpro serie_to_profile(
        const Tser& serie,
        size_t size,
        const typename Tser::axis_type& bin_size,
        const typename Tser::axis_type& start_value
)
{
	try
	{
		Tpro result(size);

		for (size_t i = 0; i < size; ++i)
		{
			result[i] = serie.interp_val(i * bin_size + start_value);
		}
		result["bin_size"] = bin_size;
		result["start_value"] = start_value;

		return result;
	}
	catch (...)
	{
		func_err("serie_to_profile");
		throw;
	}
}

// no_interp version, require Tser::[]
template<class Tpro, class Tser>
Tpro serie_to_profile_no_interp(
        const Tser& serie,
        size_t size,
        const typename Tser::axis_type& bin_size,
        const typename Tser::axis_type& start_value
)
{
	try
	{
		Tpro result(size);

		for (size_t i = 0; i < size; ++i)
		{
			result[i] = serie[i * bin_size + start_value];
		}
		result["bin_size"] = bin_size;
		result["start_value"] = start_value;

		return result;
	}
	catch (...)
	{
		func_err("serie_to_profile_no_interp");
		throw;
	}
}

}

#endif

